package com.linxiao.hrcrm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.linxiao.hrcrm.vo.ArticleTypeVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.linxiao.hrcrm.domain.ArticleType;
import com.linxiao.hrcrm.service.IArticleTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章类型Controller
 *
 * @author zhoudong
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/article/type")
public class ArticleTypeController extends BaseController {
    @Autowired
    private IArticleTypeService articleTypeService;

    /**
     * 查询文章类型列表
     */
    @PreAuthorize("@ss.hasPermi('article:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleType articleType) {
        startPage();
        List<ArticleType> list = articleTypeService.selectArticleTypeList(articleType);
        return getDataTable(list);
    }

    /**
     * 获取所有的标签
     * @param articleTypeVO
     * @return
     */
    @GetMapping("/all")
    public AjaxResult all(ArticleTypeVO articleTypeVO) {
        List<ArticleTypeVO> list = articleTypeService.selectAll(articleTypeVO);
        return success(list);
    }

    /**
     * 导出文章类型列表
     */
    @PreAuthorize("@ss.hasPermi('article:type:export')")
    @Log(title = "文章类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleType articleType) {
        List<ArticleType> list = articleTypeService.selectArticleTypeList(articleType);
        ExcelUtil<ArticleType> util = new ExcelUtil<ArticleType>(ArticleType.class);
        util.exportExcel(response, list, "文章类型数据");
    }

    /**
     * 获取文章类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(articleTypeService.selectArticleTypeById(id));
    }

    /**
     * 新增文章类型
     */
    @PreAuthorize("@ss.hasPermi('article:type:add')")
    @Log(title = "文章类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleType articleType) {
        return toAjax(articleTypeService.insertArticleType(articleType));
    }

    /**
     * 修改文章类型
     */
    @PreAuthorize("@ss.hasPermi('article:type:edit')")
    @Log(title = "文章类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleType articleType) {
        return toAjax(articleTypeService.updateArticleType(articleType));
    }

    /**
     * 删除文章类型
     */
    @PreAuthorize("@ss.hasPermi('article:type:remove')")
    @Log(title = "文章类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(articleTypeService.deleteArticleTypeByIds(ids));
    }
}
